<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>postmessage</title>
</head>
<body>
<h1>iframe:</h1>
<iframe id="iframe" src="accept_contentWindow.html" style="width: 100%; height: 300px;"></iframe>
 <input id="msg" type="text" placeholder="请输入要发送的消息">
 <button id="send">发送</button>

<script>
    window.onload =function() {
        document.getElementById('send').onclick = function() {
            var msg = document.getElementById('msg').value;
            var iframeWindow = document.getElementById('iframe').contentWindow;
            iframeWindow.postMessage(msg, "http://localhost:8666");
        }
    }
</script>
</body>
</html>